﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;
namespace BudgetManager.Domain
{
    public class AccountManager
    {
        static List<Account> accounts = new List<Account>();
 
      

        public static void InitializeAccountManager()
        {
            Goal goal = new Goal { Description = "Poupar", StartDate = DateTime.Now, EndDate = DateTime.Now, Alert = 80, Category=Category.ReadDefaultCategory() };
            accounts.Add(new Account(1,"Daniel Ribeiro", "1234","Pessoal",goal));
            accounts.Add(new Account(2,"Rodolfo Morgado", "1234","Gestão do orçamento familiar",goal));
            accounts.Add(new Account(3,"Eduardo Castanho", "1234","Pessoal",goal));

            //Set defaul Account - For tests
            SelectedAccount = accounts[0];


        }
        public static void CreateAccount(String name, String password, String description)
        {
            int newId = accounts.Count + 1;
            accounts.Add(new Account(newId,name, password, description));
        }
        public static Account getLast()
        {

            return accounts.Last();

        }
        public static void EditAccount(int id, string name, string description, string pin)
        {

            for (int i = 0; i < accounts.Count; i++)
            {
                if (accounts[i].Id == id){
                    accounts[i].Name = name;
                    accounts[i].Description = description;
                    accounts[i].Pin = pin;
                    break;
                 }
            }
        }
        public static List<Account> ReadAllAccounts()
        {
            return accounts;
        }

        public Account ReadAccountByName(String name)
        {
            foreach(Account account in ReadAllAccounts()){
                if (account.Name.Equals(name)){
                       return account;
                }
            }
            return null;
        }
        public static Account SelectedAccount { get; set; }

      
    }
}

